﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.Models.Poll>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Run
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
    var actionList = new Array();
    <% var questions = Model.questions.Where(m => m.deletionTime == null).ToList<dbPoll_Application.Models.Question>();
       for (int i = questions.Count() - 1; i > -1; i--)
       {
           if (questions[i].comparisonChart.active)
           { %>
               actionList.push(new Array("/Report/ComparativeChartWeb?pollID=<%= Model.pollID %>&questionID=<%= questions[i].questionID %>", "/Report/ComparativeChart?pollID=<%= Model.pollID %>&questionID=<%= questions[i].questionID %>", "-1", "none"));
           <% }
           if (questions[i].resultsChart.active)
           { %>
               actionList.push(new Array("/Report/ResultsChartWeb?pollID=<%= Model.pollID %>&questionID=<%= questions[i].questionID %>", "/Report/ResultsChart?pollID=<%= Model.pollID %>&questionID=<%= questions[i].questionID %>", "-1", "none"));
           <% } %>
               actionList.push(new Array("/Respond/<%= questions[i].type %>Question?pollID=<%= Model.pollID %>&questionNumber=<%= questions[i].questionNumber %>", "/Screen/Question?pollID=<%= Model.pollID %>&questionNumber=<%= questions[i].questionNumber %>", "<%= questions[i].questionID %>", "<%= questions[i].GetKeypadResponseType() %>"));
       <% } %>
    <% var testQuestions = Model.linkedPoll.questions.Where(m => m.deletionTime == null).ToList<dbPoll_Application.Models.Question>();
       for (int i = testQuestions.Count() - 1; i > -1; i--)
       {
           if (testQuestions[i].comparisonChart.active)
           { %>
               actionList.push(new Array("/Report/ComparativeChartWeb?pollID=<%= Model.linkedPoll.pollID %>&questionID=<%= testQuestions[i].questionID %>", "/Report/ComparativeChart?pollID=<%= Model.linkedPoll.pollID %>&questionID=<%= testQuestions[i].questionID %>", "-1", "none"));
           <% }
           if (testQuestions[i].resultsChart.active)
           { %>
               actionList.push(new Array("/Report/ResultsChartWeb?pollID=<%= Model.linkedPoll.pollID %>&questionID=<%= testQuestions[i].questionID %>", "/Report/ResultsChart?pollID=<%= Model.linkedPoll.pollID %>&questionID=<%= testQuestions[i].questionID %>", "-1", "none"));
           <% } %>
               actionList.push(new Array("/Respond/<%= questions[i].type %>Question?pollID=<%= Model.linkedPoll.pollID %>&questionNumber=<%= testQuestions[i].questionNumber %>", "/Screen/Question?pollID=<%= Model.linkedPoll.pollID %>&questionNumber=<%= testQuestions[i].questionNumber %>", "<%= testQuestions[i].questionID %>", "<%= testQuestions[i].GetKeypadResponseType() %>"));
       <% } %>
    actionList.push(new Array("/Respond/ResponseQuestions?pollID=<%= Model.pollID %>", "/Screen/KeypadTest?pollID=<%= Model.pollID %>&show=Name", "-2", "gridResponse"));
</script>
<script type="text/javascript" src="../../Scripts/ResponseHandler.js"></script>
<% var testPoll = ViewData["testPoll"] as String;
   if (testPoll == "true")
   { %>
       <script type="text/javascript">var testPoll = true;</script>    
   <% } 
   else
   { %>
      <script type="text/javascript">var testPoll = false;</script>  
   <% } %>
<script type="text/javascript" src="../../Scripts/Poll-Run.js"></script>
    <script type="text/javascript">
        function keypadListenerError() {
            $('#receiverErrorDialogContainer').removeClass("none");
        }
    </script>
<script type="text/javascript" src="http://www.java.com/js/deployJava.js"></script>
    <div>
        <script type="text/javascript">
            var attributes = { code: 'KeypadListener', width: 0, height: 0 };
            var parameters = { jnlp_href: '/keypadlistener-applet.jnlp', pollChannel: '<%= Model.receiverChannel %>' };
            deployJava.runApplet(attributes, parameters, '1.6'); 
        </script>
    </div>
<div id="chartScript">
<% Html.RenderPartial("ResultsChartScript", ViewData["results"] as List<int[]>); %>
</div>
    <div class="pageHeadingContainer"><h2 class="pageHeading">Run Poll</h2></div>
    <div id="contentContainer">
        <p><%= Html.ActionLink("Polls > ", "Index", "Poll", null, new { @class = "breadcrumb" })%><%= Model.name%></p>
        <div id="pageMenuContainer">
            <% var pollRoles = ViewData["pollRoles"] as ICollection<dbPoll_Application.Models.Role>;
               var pollAdministrator = new dbPoll_Application.Models.Role("Poll Administrator");
               var pollCreator = new dbPoll_Application.Models.Role("Poll Creator");
               var pollMaster = new dbPoll_Application.Models.Role("Poll Master"); %>
            <span id="launchScreen">Screen Version: <%= Html.ActionLink("[launch]", "KeypadTest", "Screen", new { pollID = Model.pollID, show = "Name" }, null)%></span>
            <ul id="pageMenu">
                <li><%= Html.ActionLink("Details", "Questions", new { pollID = Model.pollID }) %></li>
                <li>Run</li>
                <li><%= Html.ActionLink("Test", "Test", new { pollID = Model.pollID }) %></li>
                <li><%= Html.ActionLink("Reports", "Reports", new { pollID = Model.pollID })%></li>
                <li><%= Html.ActionLink("Manage Hierarchy", "EntityHierarchy", new { pollID = Model.pollID })%></li>
            </ul>
        </div>
        <%= Html.HiddenFor(m => m.pollID) %>
        <div id="controlArrowContainer">
            <span class="controlArrow"><img src="../../Resources/rightarrow.png" id="controlArrow" /></span>
        </div>
        <div id="pollQuestionsContainer">
            <span class="pollObject greenBorder"></span>
            <% 
               foreach (var question in testQuestions)
               { %>
            <span class="pollObject" title="<%= question.question %>">T<%= question.questionNumber %></span>
                 <% if (question.resultsChart.active)
                    { %>
            <span class="pollObject" style="background-image:url('../../Resources/piechart.png')"></span>
                    <% }
                    if (question.comparisonChart.active)
                    { %>
            <span class="pollObject" style="background-image:url('../../Resources/barchart.png')"></span>
                 <% }
               } %>
            <% 
               foreach (var question in questions)
               { %>
            <span class="pollObject" title="<%= question.question %>">Q<%= question.questionNumber %></span>
                 <% if (question.resultsChart.active)
                    { %>
            <span class="pollObject" style="background-image:url('../../Resources/piechart.png')"></span>
                    <% }
                    if (question.comparisonChart.active)
                    { %>
            <span class="pollObject" style="background-image:url('../../Resources/barchart.png')"></span>
                 <% }
               } %>
            <span class="pollObject">E</span>
        </div>
        <div class="clear"></div>
        <div id="participantsContainer">
            <div id="publicMessageContainer">
                <%= Html.TextArea("publicMessage", "Enter a message to send to all web users...", new { @class = "publicMessage" }) %>
                <div id="chartContainer"></div>
                <div class="clear"></div>
                <input type="button" id="publicMessageButton" value="Send" /><span id="errorMessage"></span>
            </div>
            <div id="participantMonitor">
                <table class="questions">
                    <tr>
                        <th id="runDeviceIDCol">DeviceID</th>
                        <th id="runFirstnameCol">First name</th>
                        <th id="runLastnameCol">Last name</th>
                        <th id="runPerformanceCol">Participation</th>
                        <th id="runMessageCol"></th>
                    </tr>
                    <% foreach (var participant in Model.participants)
                       {
                           if (participant.isTestParticipant && testPoll == "false")
                           {
                               continue;
                           } %>
                       <tr>
                           <td><%= participant.deviceID %></td>
                           <td><%= participant.firstName %></td>
                           <td><%= participant.lastName %></td>
                           <td>
                               <table class="performanceTable">
                                   <tr>
                                   <% for (int i = 0; i < questions.Count(); i++)
                                      { %>
                                      <td id="<%= participant.deviceID + questions[i].questionID %>"></td>
                                   <% } %>
                                   </tr>
                               </table>
                           </td>
                           <% if (participant.linkedUser != null)
                              { %>
                           <td><input type="button" class="privateMessageButton" value="Message" /><span class="none"><%= participant.linkedUser.UserName %></span></td>
                           <% }
                              else
                              { %>
                           <td><input type="button" id="Button1" value="Message" disabled="disabled" /></td>
                           <% } %>
                       </tr>
                    <% } %>
                </table>
            </div>
        </div>
        <div id="privateMessageDialog" class="none"><div>To: <span id="privateMessageDeviceID"></span><span id="privateMessageFirstName"></span> <span id="privateMessageLastName"></span></div><%= Html.TextArea("privateMessage", new { id = "privateMessage" }) %><div class="clear"></div><input type="button" id="sendPrivateMessage" value="Send" /><input type="button" id="cancelPrivateMessage" value="Cancel" /></div>
        <div id="receiverErrorDialogContainer" class="none">
            <div id="receiverErrorDialog">
                <div id="receiverErrorHeading">Receiver Error</div>
                <div id="receiverErrorContent">No receiver has been detected. Please ensure that it has been plugged in and click OK.
                    <div id="receiverErrorButtons"><input type="button" id="receiverErrorOK" value="OK" /><input type="button" id="receiverErrorCancel" value="Cancel" /></div>
                </div>
            </div>
        </div>
    </div>

</asp:Content>
